package com.six.controller;

import com.six.service.ChartsService;
import com.six.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("charts")
@CrossOrigin
public class ChartsController {
    @Autowired
    ChartsService chartsService;
    @RequestMapping("chartsA")
    public Result chartsA() {
        List<HashMap> list = chartsService.chartsA();
        System.out.println(list);
        List supplynameList=new ArrayList<>();
        List sumList=new ArrayList<>();
        List pname=new ArrayList<>();
        for (HashMap item:list){
            supplynameList.add( item.get("supplyname"));
            sumList.add(item.get("sum"));
            pname.add(item.get("pname"));

        }
        Map map=new HashMap();
        map.put("supplyname",supplynameList);
        map.put("sum",sumList);
        map.put("pname",pname);
        return Result.success(map);

    }
    @RequestMapping("chartsB")
    public Result chartsB() {
        List<HashMap> list = chartsService.chartsB();
        System.out.println(list);
        return Result.success(list);
    }
}
